package edu.ynu.se.xiecheng.achitectureclass.service;

import edu.ynu.se.xiecheng.achitectureclass.dao.GreenhouseDao;
import edu.ynu.se.xiecheng.achitectureclass.entity.Greenhouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GreenhouseServiceImpl implements IGreenhouseService {

    @Autowired
    private GreenhouseDao greenhouseDao;

    @Override
    public Greenhouse save(Greenhouse greenhouse) {
        return greenhouseDao.save(greenhouse);
    }

    @Override
    public Greenhouse findById(Long id) {
        return greenhouseDao.findById(id).orElse(null);
    }

    @Override
    public List<Greenhouse> findAll() {
        return greenhouseDao.findAll();
    }

    @Override
    public void delete(Long id) {
        Greenhouse greenhouse = findById(id);
        if (greenhouse != null) {
            greenhouse.setIsDeleted(1);
            greenhouseDao.save(greenhouse);
        }
    }

    @Override
    public String getBoxNoById(Long id) {
        Greenhouse greenhouse = findById(id);
        return greenhouse != null ? greenhouse.getBoxNo() : null;
    }
} 